home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
C⁄C++
/
Marathon Map Viewer
/
@Source
/
chunkStorage.cpp
next >
Wrap
Text File
|
1995-06-05
|
1KB
|
47 lines
/*-----------------------------------------------------------------
-----------------------------------------------------------------*/
#include "chunkStorage.h"
/*-----------------------------------------------------------------
Reads in the requested chunk and returns a ptr to it.
Assumes next chunk offset for last chunk is 0;
-----------------------------------------------------------------*/
Ptr readChunk(short fileRefNum, long type, levelInfo *theLevelInfo, short levelNum)
{
long levelOffset = theLevelInfo[levelNum].offset;
long levelSize = theLevelInfo[levelNum].size;
chunkHeader theChunk;
long count;
Ptr chunkData = nil;
SetFPos(fileRefNum, fsFromStart, levelOffset);
do {
count = sizeof(chunkHeader);
ThrowIfOSErr_(FSRead(fileRefNum, &count, &theChunk));
if (theChunk.chunkType == type)
{
count = theChunk.size;
chunkData = NewPtrClear(count); // could fail I suppose
if (chunkData)
ThrowIfOSErr_(FSRead(fileRefNum, &count, chunkData));
break;
}
SetFPos(fileRefNum, fsFromStart, levelOffset + theChunk.nextChunk);
} while (theChunk.nextChunk);
return chunkData;
}